function getExplorerType() {
	var explorer = window.navigator.userAgent;
	if (explorer.indexOf("MSIE") >= 0) {// IE
		return "IE";
	} else if (explorer.indexOf("Firefox") >= 0) {// Firefox
		return "Firefox";
	} else if (explorer.indexOf("Chrome") >= 0) {// Chrome
		return "Chrome";
	} else if (explorer.indexOf("Opera") >= 0) {// Opera
		return "Opera";
	} else if (explorer.indexOf("Safari") >= 0) {// Safari
		return "Safari";
	} else {
		return "Unknowned";
	}
}

function alertExplorerType() {
	if (getExplorerType() == "IE") {
		// 利用对话框返回的值 （true 或者 false）
		if (confirm("您正在使用IE浏览器，为了更好的显示效果，请使用Firefox或者Chrome浏览器.")) {
			window.open("http://www.firefox.com.cn/download/");
		}
	}
}

var getXMLHttpRequest = function(){
	var xhr=null;
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xhr;
}

var httpRequestGet = function(url, async, onloadFunc) {
	var xhr = getXMLHttpRequest();
	if(async==true){
		xhr.open('GET', url, true);
	}else{
		xhr.open('GET', url, false);
	}
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.setRequestHeader('Accept', 'application/json');
	xhr.onreadystatechange= function() {
		if (xhr.status == 0) {
			// mui.toast("网络不给力！！！");
			return;
		} else if (xhr.status == 200) {
			onloadFunc(xhr);
		} else if (xhr.status == 404) {
			// mui.toast("服务器错误，错误代码:" + xhr.status);
			return;
		}
	};
	xhr.onerror = function() {
		if (xhr.status == 0) {
			// mui.toast("网络不给力！！！");
			return;
		}
	}
	xhr.send();
}

var httpRequestGetJson = function(url, async, onloadFunc) {
	var xhr = getXMLHttpRequest();
	if(async==true){
		xhr.open('GET', url, true);
	}else{
		xhr.open('GET', url, false);
	}
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.setRequestHeader('Accept', 'application/json');
	xhr.onreadystatechange= function() {
		if (xhr.status == 0) {
			// mui.toast("网络不给力！！！");
			return;
		} else if (xhr.status == 200) {
			onloadFunc(JSON.parse(xhr.responseText));
		} else if (xhr.status == 404) {
			// mui.toast("服务器错误，错误代码:" + xhr.status);
			return;
		}
	};
	xhr.onerror = function() {
		if (xhr.status == 0) {
			// mui.toast("网络不给力！！！");
			return;
		}
	}
	xhr.send();
}

var httpRequestPost = function(url, sendJson, async, onloadFunc) {
	var xhr = getXMLHttpRequest();
	if(async==true){
		xhr.open('POST', url, true);
	}else{
		xhr.open('POST', url, false);
	}
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.setRequestHeader('Accept', 'application/json');
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			onloadFunc(xhr);
		} else {
			return;
		}
	};
	xhr.send(sendJson);
}

var httpRequestPostJson = function(url, sendJson, async, onloadFunc) {
	sendJson = JSON.stringify(sendJson);
	var xhr = getXMLHttpRequest();
	if(async==true){
		xhr.open('POST', url, true);
	}else{
		xhr.open('POST', url, false);
	}
	xhr.setRequestHeader('Content-Type', 'application/json');
	xhr.setRequestHeader('Accept', 'application/json');
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			onloadFunc(JSON.parse(xhr.responseText));
		} else {
			return;
		}
	};
	xhr.send(sendJson);
}

var del = function(id) {
	if (window.confirm("你确定删除吗？")) {
		var url = "delete/" + id + ".do";
		var entity = {};
		var onloadFunc = function(result) {
			if (result.isSuccess == true) {
				history.go(0);
			} else {
				alert("删除失败！");
			}
		};

		httpRequestPostJson(url, entity, false, onloadFunc);
	}
}

function toJson(obj) {
	return JSON.stringify(obj);
}
function fromJson(val) {
	return JSON.parse(val);
}

function getSelectedArray(name) {
	var items = document.getElementsByName(name);
	var result = [];
	var count = 0;
	for (var i = 0; i < items.length; i++) {
		if (items[i].checked) {
			result[count] = items[i].value;
			count++;
		}
	}
	return result;
}
function checkAll(name) {
	var items = document.getElementsByName(name);
	var checked = !items[0].checked;
	for (var i = 0; i < items.length; i += 1) {
		items[i].checked = checked;
	}
}
//选中
function ListCheckAll(obj){
	if(obj.checked){
		$('input[name=id]').prop('checked','true');
	}else{
		$('input[name=id]').removeAttr('checked');
	}
}
function ListCheck(obj){
	var list=$('input[name=id]');
	var val=(function (){
		for(var i=0;i<list.length;i++){
			if(list[i].checked){
				
			}else{
				return;
			}
		}
		return true;
	})();
	if(obj.checked && val==true){
		$('#selectAll').prop('checked','true');
	}else{
		$('#selectAll').removeAttr('checked');
	}
}